import { _decorator, Component, Label, Button } from 'cc';
import RowFallClear_StartPanel from "./RowFallClear_StartPanel";
import RowFallClear_GameManager from '../Manager/RowFallClear_GameManager';
// import RowFallClear_GameManager from "../Manager/GameManager";

const { ccclass, property } = _decorator;

@ccclass('RowFallClear_WinLosePanel')
export default class RowFallClear_WinLosePanel extends Component {
    public static Instance: RowFallClear_WinLosePanel;
    @property(Label)
    Label_win: Label | null = null;
    @property(Label)
    Label_lose: Label | null = null;
    @property(Label)
    Label_score: Label | null = null;

    @property(Button)
    Button_close: Button | null = null;
    @property(Button)
    Button_main: Button | null = null;
    @property(Button)
    Button_replay: Button | null = null;
    state: number;
    onLoad() {
        RowFallClear_WinLosePanel.Instance = this;
    }
    start() {
        this.Button_close.node.on('click', this.click_close, this);
        this.Button_main.node.on('click', this.click_main, this);
        this.Button_replay.node.on('click', this.click_replay, this);
    }
    ShowOn(_state: number) {
        this.node.active = true;
        this.state = _state;
        this.Label_win.node.active = this.state == 1;
        this.Label_lose.node.active = this.state == 2;
        this.RefreshScore(RowFallClear_GameManager.Instance.score);
    }
    ShowOff() {
        this.node.active = false;
    }
    RefreshScore(_score: number) {
        this.Label_score.string = _score.toString();
    }
    click_close(button) {
        this.ShowOff();
        RowFallClear_GameManager.Instance.GameOver();
        RowFallClear_StartPanel.Instance.ShowOn();
    }
    click_main(button) {
        this.ShowOff();
        RowFallClear_GameManager.Instance.GameOver();
        RowFallClear_StartPanel.Instance.ShowOn();
    }
    click_replay(button) {
        this.ShowOff();
        RowFallClear_GameManager.Instance.GameStart();
    }
}